home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
lisp
/
kcl
/
akcl
/
akcl-1-6.lha
/
V
/
c
/
array.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-07
|
15KB
|
747 lines
Changes file for /usr/local/src/kcl/c/array.c
Created on Mon Oct 7 20:47:14 1991
Usage \n@s[Original text\n@s|Replacement Text\n@s]
See the file rascal.ics.utexas.edu:/usr2/ftp/merge.c
for a program to merge change files. Anything not between
"\n@s[" and "\n@s]" is a simply a comment.
This file was constructed using emacs and merge.el
Enhancements Copyright (c) W. Schelter All rights reserved.
by (Bill Schelter) wfs@carl.ma.utexas.edu
****Change:(orig (16 16 a))
@s[#define ATOTLIM 16*1024*1024
@s|#define ATOTLIM 16*1024*1024
#define WSIZE CHAR_SIZE*sizeof(fixnum)
@s]
****Change:(orig (18 18 d))
@s[
@s|
@s]
****Change:(orig (31 31 c))
@s[ else if (x == Slong_float)
@s| else if (x == Slong_float || x == Ssingle_float || x==Sdouble_float)
@s]
****Change:(orig (32 32 a))
@s[ return(aet_lf);
@s| return(aet_lf);
else if (x == Sunsigned_char)
return(aet_uchar);
else if (x == Sunsigned_short)
return(aet_ushort);
else if (x == Ssigned_char)
return(aet_char);
else if (x == Ssigned_short)
return(aet_short);
@s]
****Change:(orig (67 67 a))
@s[ return((char *)(x->a.a_self + inc));
@s| return((char *)(x->a.a_self + inc));
case aet_char:
case aet_uchar:
@s]
****Change:(orig (70 70 a))
@s[ return(x->st.st_self + inc);
@s| return(x->st.st_self + inc);
case aet_short:
case aet_ushort:
return ((char *)&(USHORT(x,inc)));
@s]
****Change:(orig (72 72 a))
@s[ return((char *)(x->lfa.lfa_self + inc));
@s| return((char *)(x->lfa.lfa_self + inc));
default:
FEerror("Bad array type",0);
@s]
****Change:(orig (76 77 c))
@s[array_allocself(x, staticp)
object x;
@s|static object DFLT_aet_object = Cnil;
static char DFLT_aet_ch = ' ';
static char DFLT_aet_char = 0;
static int DFLT_aet_fix = 0 ;
static short DFLT_aet_short = 0;
static shortfloat DFLT_aet_sf = 0.0;
static longfloat DFLT_aet_lf = 0.0;
char * default_aet_types[] =
{ (char *) &DFLT_aet_object, /* t */
(char *) &DFLT_aet_ch, /* string-char */
(char *) &DFLT_aet_fix, /* bit */
(char *) &DFLT_aet_fix, /* fixnum */
(char *) &DFLT_aet_sf, /* short-float */
(char *) &DFLT_aet_lf, /* long-float */
(char *) &DFLT_aet_char, /* signed char */
(char *) &DFLT_aet_char, /* unsigned char */
(char *) &DFLT_aet_short, /* signed short */
(char *) &DFLT_aet_short, /* unsigned short */
};
/* RAW_AET_PTR returns a pointer to something of raw type obtained from X
suitable for using GSET for an array of elt type TYP.
If x is the null pointer, return a default for that array element
type.
*/
char *
raw_aet_ptr(x,typ)
short typ;
object x;
{ /* doubles are the largest raw type */
static double u;
if (x==Cnil) return default_aet_types[typ];
switch (typ){
#define STORE_TYPED(pl,type,val) *((type *) pl) = (type) val; break;
case aet_object: STORE_TYPED(&u,object,x);
case aet_ch: STORE_TYPED(&u,char, char_code(x));
case aet_bit: STORE_TYPED(&u,fixnum, -fix(x));
case aet_fix: STORE_TYPED(&u,fixnum, fix(x));
case aet_sf: STORE_TYPED(&u,shortfloat, sf(x));
case aet_lf: STORE_TYPED(&u,longfloat, lf(x));
case aet_char: STORE_TYPED(&u, char, fix(x));
case aet_uchar: STORE_TYPED(&u, unsigned char, fix(x));
case aet_short: STORE_TYPED(&u, short, fix(x));
case aet_ushort: STORE_TYPED(&u,unsigned short,fix(x));
default: FEerror("bad elttype",0);
}
return (char *)&u;
}
/* GSET copies into array ptr P1, the value
pointed to by the ptr VAL into the next N slots. The
array type is typ. If VAL is the null ptr, use
the default for that element type
NOTE: for type aet_bit n is the number of Words
ie (nbits +WSIZE-1)/WSIZE and the words are set.
*/
gset(p1,val,n,typ)
char *p1,*val;
int n;
int typ;
{ if (val==0)
val = default_aet_types[typ];
switch (typ){
#define GSET(p,n,typ,val) {typ x = *((typ *) val); GSET1(p,n,typ,x)}
#define GSET1(p,n,typ,val) while (n-- > 0) \
{ *((typ *) p) = val; \
p = p + sizeof(typ); \
} break;
case aet_object: GSET(p1,n,object,val);
case aet_ch: GSET(p1,n,char,val);
/* Note n is number of fixnum WORDS for bit */
case aet_bit: GSET(p1,n,fixnum,val);
case aet_fix: GSET(p1,n,fixnum,val);
case aet_sf: GSET(p1,n,shortfloat,val);
case aet_lf: GSET(p1,n,longfloat,val);
case aet_char: GSET(p1,n,char,val);
case aet_uchar: GSET(p1,n,unsigned char,val);
case aet_short: GSET(p1,n,short,val);
case aet_ushort: GSET(p1,n,unsigned short,val);
default: FEerror("bad elttype",0);
}
}
#ifndef COM_LENG
#define COM_LENG
#endif
extern short aet_sizes[COM_LENG];
#define W_SIZE (CHAR_SIZE*sizeof(fixnum))
/* This copies from p1 to p2 n elements of typ
gcopy(p1,p2,n,typ)
char *p1,*p2;
int n,typ;
{ if(typ== (int)aet_bit)
bcopy(p1,p2,(n+CHAR_SIZE-1)/CHAR_SIZE);
else
bcopy(p1,p2,n*aet_sizes[(int) typ]);
}
*/
/* Copy n1 elements from x to y starting at x[i1] to x[i2]
If the types of the arrays are not the same, this has
implementation dependent results.
*/
copy_array_portion(x,y,i1,i2,n1)
object x,y; int i1,i2,n1;
{ enum aelttype typ1=array_elttype(vs_base[0]);
enum aelttype typ2=array_elttype(vs_base[1]);
int nc;
if (typ1==aet_bit)
{if (i1 % CHAR_SIZE)
badcopy:
FEerror("Bit copies only if aligned");
else
{int rest=n1%CHAR_SIZE;
if (rest!=0 )
{if (typ2!=aet_bit)
goto badcopy;
{while(rest> 0)
{ aset1(y,i2+n1-rest,(aref1(x,i1+n1-rest)));
rest--;}
}}
i1=i1/CHAR_SIZE ;
n1=n1/CHAR_SIZE;
typ1=aet_char;
}};
if (typ2==aet_bit)
{if (i2 % CHAR_SIZE)
goto badcopy;
i2=i2/CHAR_SIZE ;}
if ((typ1 ==aet_object ||
typ2 ==aet_object) && typ1 != typ2)
FEerror("Can't copy between different array types");
nc=n1 * aet_sizes[(int)typ1];
if (i1+n1 > x->a.a_dim
|| ((y->a.a_dim - i2) *aet_sizes[(int)typ2]) < nc)
FEerror("Copy out of bounds");
bcopy(x->ust.ust_self + (i1*aet_sizes[(int)typ1]),
y->ust.ust_self + (i2*aet_sizes[(int)typ2]),
nc);
}
/* Copy from X to Y starting at indices i1 and i2 and
going optional N places (or array-total-size(x) -i1)
if not specified
*/
siLcopy_array_portion()
{int n;
if (vs_top-vs_base == 5)
{n=fix(vs_base[4]);}
else
{check_arg(4);
if(type_of(vs_base[3]) !=t_fixnum ||
type_of(vs_base[2]) !=t_fixnum )
FEerror("Need fixnum index");
n= vs_base[0]->a.a_dim - fix(vs_base[2]);
}
copy_array_portion(vs_base[0],vs_base[1],fix(vs_base[2]),
fix(vs_base[3]),n);
vs_top=vs_base+1;
}
/* X is the header of an array. This supplies the body which
will not be relocatable if STATICP. If DFLT is 0, do not
initialize (the caller promises to reset these before the
next gc!). If DFLT == Cnil then initialize to default type
for this array type. Otherwise DFLT is an object and its
value is used to init the array */
array_allocself(x, staticp,dflt)
object x,dflt;
@s]
****Change:(orig (81 81 c))
@s[ int i, d;
char *(*f)();
@s| int i, d;
char *(*f)(),*tmp_alloc;
enum aelttype typ;
@s]
****Change:(orig (88 88 c))
@s[ switch (array_elttype(x)) {
@s| typ=array_elttype(x);
switch (typ) {
@s]
****Change:(orig (90 92 c))
@s[ x->a.a_self = (object *)(*f)(sizeof(object)*d);
for (i = 0; i < d; i++)
x->a.a_self[i] = Cnil;
@s| x->a.a_self = AR_ALLOC(*f,d,object);
@s]
****Change:(orig (94 94 d))
@s[ break;
@s| break;
@s]
****Change:(orig (96 98 c))
@s[ x->st.st_self = (*f)(d);
for (i = 0; i < d; i++)
x->st.st_self[i] = ' ';
@s| case aet_char:
case aet_uchar:
x->st.st_self = AR_ALLOC(*f,d,char);
@s]
****Change:(orig (100 100 c))
@s[ break;
@s| break;
case aet_short:
case aet_ushort:
x->ust.ust_self = (unsigned char *) AR_ALLOC(*f,d,short);
break;
@s]
****Change:(orig (102 105 c))
@s[ d = (d+7)/8;
x->bv.bv_self = (*f)(d);
for (i = 0; i < d; i++)
x->bv.bv_self[i] = '\0';
@s| d = (d+W_SIZE-1)/W_SIZE;
@s]
****Change:(orig (107 108 d))
@s[ x->bv.bv_offset = 0;
break;
@s| x->bv.bv_offset = 0;
@s]
****Change:(orig (110 112 c))
@s[ x->fixa.fixa_self = (fixnum *)(*f)(sizeof(fixnum)*d);
for (i = 0; i < d; i++)
x->fixa.fixa_self[i] = 0;
@s| x->fixa.fixa_self = AR_ALLOC(*f,d,fixnum);
@s]
****Change:(orig (114 114 d))
@s[ break;
@s| break;
@s]
****Change:(orig (116 118 c))
@s[ x->sfa.sfa_self = (shortfloat *)(*f)(sizeof(shortfloat)*d);
for (i = 0; i < d; i++)
x->sfa.sfa_self[i] = 0.0;
@s| x->sfa.sfa_self = AR_ALLOC(*f,d,shortfloat);
@s]
****Change:(orig (120 120 d))
@s[ break;
@s| break;
@s]
****Change:(orig (122 124 c))
@s[ x->lfa.lfa_self = (longfloat *)(*f)(sizeof(longfloat)*d);
for (i = 0; i < d; i++)
x->lfa.lfa_self[i] = 0.0;
@s| x->lfa.lfa_self = AR_ALLOC(*f,d,longfloat);
@s]
****Change:(orig (126 126 a))
@s[ break;
}
@s| break;
}
if(dflt!=0) gset(x->st.st_self,raw_aet_ptr(dflt,typ),d,typ);
@s]
****Change:(orig (154 154 a))
@s[ return(make_fixnum(x->fixa.fixa_self[index]));
@s| return(make_fixnum(x->fixa.fixa_self[index]));
#define UCHAR(x,index) ((x)->ust.ust_self[index])
case aet_uchar:
return(make_fixnum((fixnum)(UCHAR(x,index))));
case aet_char:
return(make_fixnum((fixnum)(SIGNED_CHAR(UCHAR(x,index)))));
case aet_short:
return(make_fixnum((fixnum)(short)USHORT(x,index)));
case aet_ushort:
return(make_fixnum((fixnum)USHORT(x,index)));
@s]
****Change:(orig (199 199 a))
@s[ x->fixa.fixa_self[index] = fixint(value);
break;
@s| x->fixa.fixa_self[index] = fixint(value);
break;
case aet_char:
case aet_uchar:
x->ust.ust_self[index]=(unsigned char)fixint(value);
break;
@s]
****Change:(orig (200 200 a))
@s[
@s|
case aet_short:
case aet_ushort:
USHORT(x,index) = (unsigned short)fixint(value);
break;
@s]
****Change:(orig (320 320 c))
@s[ from->st.st_self = array_address(to, j);
}
/*
@s| from->st.st_self = array_address(to, j);
}
/* (setq a (make-array 2 :displaced-to (setq b (make-array 4 )))) { A->displ = (B), B->displ=(nil A)}
@s]
****Change:(orig (327 328 c))
@s[ object to = from->a.a_displaced->c.c_car;
@s| object to;
/* if the cons is free, neither the FROM nor the TO array will
survive the gc (or we would have marked this), and we can
skip undisplacing */
if (from->a.a_displaced->d.m == FREE) return;
to= from->a.a_displaced->c.c_car;
@s]
****Change:(orig (332 336 c))
@s[ for (p = &(to->a.a_displaced->c.c_cdr);; p = &((*p)->c.c_cdr))
if ((*p)->c.c_car == from) {
*p = (*p)->c.c_cdr;
return;
@s, }
@s| for (p = &(to->a.a_displaced->c.c_cdr);; p = &((*p)->c.c_cdr)){
if ((*p)->d.m == FREE) return;
/* During the sweep phase we sometimes null out the rest of this list
if the array is being displaced.
*/
if (*p == Cnil) return;
if ((*p)->c.c_car == from) {
*p = (*p)->c.c_cdr;
return;
}}
@s]
****Change:(orig (410 410 c))
@s[ displaced-to displaced-index-offset
static
@s| displaced-to displaced-index-offset
static initial-element
@s]
****Change:(orig (418 418 c))
@s[ r = vs_top - vs_base - 5;
@s| r = vs_top - vs_base - 6;
@s]
****Change:(orig (428 428 c))
@s[ x->a.a_dims = (int *)alloc_relblock(sizeof(int)*r);
@s| x->a.a_dims = AR_ALLOC(alloc_relblock,r,int);
@s]
****Change:(orig (434 434 c))
@s[ if ((j = fixnnint(vs_base[i+5])) > ADIMLIM) {
@s| if ((j = fixnnint(vs_base[i+6])) > ADIMLIM) {
@s]
****Change:(orig (437 437 c))
@s[ 2, vs_head, vs_base[i+5]);
@s| 2, vs_head, vs_base[i+6]);
@s]
****Change:(orig (449 449 c))
@s[ array_allocself(x, vs_base[4] != Cnil);
@s| array_allocself(x, vs_base[4] != Cnil,vs_base[5]);
@s]
****Change:(orig (460 460 c))
@s[ displaced-to displaced-index-offset
static)
@s| displaced-to displaced-index-offset
static &optional initial-element)
@s]
****Change:(orig (465 465 a))
@s[ int d, i, j;
object x;
@s| int d, i, j;
object x;
object dflt=Cnil;
@s]
****Change:(orig (467 468 c))
@s[ enum aelttype aet;
check_arg(7);
@s| enum aelttype aet;
if (vs_top-vs_base == 8)
{dflt=vs_base[7];}
else {check_arg(7);}
@s]
****Change:(orig (488 488 c))
@s[ array_allocself(x, vs_base[6] != Cnil);
@s| array_allocself(x, vs_base[6] != Cnil,dflt);
@s]
****Change:(orig (604 604 a))
@s[ vs_base[0] = Sfixnum;
break;
@s| vs_base[0] = Sfixnum;
break;
case aet_char:
vs_base[0]= Ssigned_char;
break;
case aet_uchar:
vs_base[0]= Sunsigned_char;
break;
case aet_short:
vs_base[0]= Ssigned_short;
break;
case aet_ushort:
vs_base[0]= Sunsigned_short;
break;
@s]
****Change:(orig (774 774 a))
@s[ object old, new, displaced, dlist;
int diff;
@s| object old, new, displaced, dlist;
int diff;
struct dummy fw;
@s]
****Change:(orig (777 777 d))
@s[
check_arg(2);
@s|
check_arg(2);
@s]
****Change:(orig (779 779 a))
@s[ old = vs_base[0];
new = vs_base[1];
@s| old = vs_base[0];
new = vs_base[1];
fw = old->d;
@s]
****Change:(orig (784 784 c))
@s[ if (!old->a.a_adjustable)
@s|/* Common lisp now allows adjustment of non adjustable arrays CLTLII 17.6
if (!old->a.a_adjustable)
@s]
****Change:(orig (785 785 a))
@s[ FEerror("~S is not adjustable.", 1, old);
@s| FEerror("~S is not adjustable.", 1, old);
*/
@s]
****Change:(orig (806 806 a))
@s[ default:
goto CANNOT;
}
@s| default:
goto CANNOT;
}
/* restore the s and m fields overwritten by above assignments */
old->d = fw;
@s]
****Change:(orig (807 807 a))
@s[ old->a.a_displaced = displaced;
@s| old->a.a_displaced = displaced;
/* prevent having two arrays with the same body--which are not related
that would cause the gc to try to copy both arrays and there might
not be enough space. */
new->a.a_dim=0;
new->a.a_self=0;
@s]
****Change:(orig (847 847 c))
@s[ make_si_function("DISPLACED-ARRAY-P", siLdisplaced_array_p);
@s| make_si_function("DISPLACED-ARRAY-P", siLdisplaced_array_p);
make_si_constant("CHAR-SIZE",make_fixnum(CHAR_SIZE));
make_si_constant("SHORT-SIZE",make_fixnum(CHAR_SIZE*sizeof(short)));
@s]
****Change:(orig (850 850 c))
@s[ make_si_function("SVSET", siLsvset);
@s| make_si_function("SVSET", siLsvset);
make_si_function("COPY-ARRAY-PORTION",siLcopy_array_portion);
@s]